#!/bin/sh

set -eu

PROJECT="tvgids-nl"

rm -rf bin

if ! ant debug; then
	read -N 1 -p "Try to fix the mistake by running 'android update project' [y/n]? " answer
	echo
	if [ "$answer" == "y" ] || [ "$answer" == "Y" ]; then
		android update project -p . -n $PROJECT
		echo
		ant debug
	else
		echo "aborting..."
		exit
	fi
fi

echo
echo "**** Uploading"
adb install -r "bin/$PROJECT-debug.apk"

echo
echo "**** Start app in 1 second"
(sleep 1;adb shell am start -n nl.RvdW.$PROJECT/.$PROJECT &>/dev/null) &
echo "**** Starting logcat"
adb logcat -C -s "$PROJECT:V" "AndroidRuntime:D"
